/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2021-02-24
 * Time: 18:37
 */
#include <QtWidgets>
#include <QCoreApplication>
#include <QObject>

#define SETTING_FILE_PATH     QCoreApplication::applicationDirPath() + "/../../../config/"

void WriteSettingFile(QSettings &setting)
{
    //setting.beginGroup("Mission");
    //setting.setValue(QString::fromLocal8Bit("空中巡逻"),"阶段二SU27巡逻06号空域");
    //setting.endGroup();

    setting.beginWriteArray("Adjust/tt");
    for (int i = 0; i < 5; ++i) {
        setting.setArrayIndex(i);
        setting.setValue("unit_name", "空中巡逻");
        setting.setValue("superior_info", "阶段二SU27巡逻06号空域_->xxx");
    }
    setting.endArray();
    setting.beginWriteArray("Adjust/tt");

    for (int i = 0; i < 5; ++i) {
        setting.setArrayIndex(i);
        setting.setValue("unit_name", "空中巡逻1");
        setting.setValue("child_name", "阶段二SU27巡逻06号空域_1");
    }
    setting.endArray();
}

void ReadSettingFile(QSettings &setting)
{
    //setting.beginGroup("Mission");
    //setting.
    //qDebug()<< setting.value(QString::fromLocal8Bit("空中巡逻")).toString();
    //setting.endGroup();

    int size = setting.beginReadArray("Adjust/tt");
    for (int i = 0; i < size; ++i) {
        setting.setArrayIndex(i);
        qDebug() << setting.value("unit_name").toString()
                 << setting.value("superior_info").toString();
    }

}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QSettings setting(SETTING_FILE_PATH + "setting.txt", QSettings::IniFormat);
    setting.setIniCodec("utf8");
    setting.clear();
    WriteSettingFile(setting);
    ReadSettingFile(setting);
    return a.exec();
}